//
//  ChooseDataTimeViewController.m
//  PropertyManager
//
//  Created by TNG on 2018/8/15.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "ChooseDataTimeViewController.h"

@interface ChooseDataTimeViewController ()

@property (strong, nonatomic) UIDatePicker * datePicker;
@property (strong, nonatomic) UIButton * btn;

@end

@implementation ChooseDataTimeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"年月日";
    [self.view addSubview:self.datePicker];
    self.datePicker.datePickerMode = UIDatePickerModeDate;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy年MM月dd日"];
    if(self.str)
    {
        NSDate *dateFromString = [[NSDate alloc] init];
        dateFromString = [dateFormatter dateFromString:self.str];
        if (dateFromString) [self.datePicker setDate:dateFromString];
    }
    [self.view addSubview:self.btn];
}

-(UIDatePicker *)datePicker
{
    if (_datePicker == nil)
    {
        _datePicker   = [[UIDatePicker alloc] init];
        _datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
        _datePicker.backgroundColor = [UIColor whiteColor];
        // UIDatePicker默认高度216
        _datePicker.frame = CGRectMake(0, kStatusAndNavBarH + 80 , WIDTH , _datePicker.frame.size.height);
    }
    return _datePicker;
}

-(UIButton *)btn
{
    if (_btn == nil) {
        _btn = [[UIButton alloc] initWithFrame:CGRectMake(40, CGRectGetMaxY(self.datePicker.frame)+40, WIDTH-80, 40)];
        _btn.titleLabel.font = font(17);
        [_btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_btn setTitle:@"提交" forState:0];
        _btn.layer.cornerRadius = 4;
        [_btn setBackgroundColor:[UIColor redColor]];
    }
    return _btn;
}

-(void)btnClick:(UIButton *)btn
{
    NSDate *selectData = self.datePicker.date;
    self.sendChooseTimeBlock(selectData);
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
